var app=angular.module('dzsw', ['pagination']);//定义模块
app.controller('tbContentController' ,function($scope,$controller,$http){
    $controller('baseController',{$scope:$scope});//继承
    //分页
    $scope.findPage=function(pageNum,pageSize){
        $http.post('../tbContent/pagelist.do?pageSize='+pageSize+"&pageNum="+pageNum,$scope.searchEntity).success(
            function(response){
                $scope.list=response.rows;
                $scope.paginationConf.totalItems=response.total;//更新总记录数
            }
        );
    }
    $scope.save=function() {
        $http.post('../tbContent/save.do',$scope.entity).success(
            function(response){
                if(response.success){
                    $scope.reloadList();
                }
            }
        );
    }
    $scope.getById=function (id) {
        $http.get('../tbContent/getById.do?id='+id).success(
            function(response){
                $scope.entity=response;
            }
        );
    }

    $scope.deletbth=function () {
        if($scope.selectIds.length == 0){
            alert("请选择要删除的数据");
        } else{
            if(confirm("您确认要删除吗？")){
                $http.get('../tbContent/deletebth.do?ids='+$scope.selectIds).success(
                    function(response){
                        $scope.reloadList();
                    }
                );
            }
        }
    }
    //查询所有分类
    $scope.getTypes=function () {
        console.log(111);
        $http.get('../tbContentCategory/list.do').success(
            function(response){
                $scope.typelist=response;
                console.log(response);
            }
        );
    }

    //上传
    $scope.uploadfile=function () {
       // debugger;
        var formData=new FormData();
        formData.append("multipartFile",file.files[0]);
        $http({
            method:'POST',
            url:"../file/uplaod.do",
            data: formData,
            headers: {'Content-Type':undefined},//anjularjs对于post和get请求默认的Content-Type header 是application/json。通过设置‘Content-Type’: undefined，这样浏览器会帮我们把Content-Type 设置为 multipart/form-data.
            transformRequest: angular.identity //通过设置 transformRequest: angular.identity ，anjularjs transformRequest function 将序列化我们的formdata object.
        }).success(
            function(response) {
                alert("上传成功");
                console.log(response.imgsrc);
                $scope.entity.pic=response.imgsrc;
            }
        );
    }
});